package ekahau.positioning.services.providor.client;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.Socket;
import java.net.UnknownHostException;

import ekahau.positioning.services.providor.ServicesClientRequest;
import ekahau.positioning.services.providor.ServicesClientRequest.ZONE_TYPE;
import ekahau.positioning.services.providor.ServicesClientResponse;
import ekahau.ue.registration.RegistrationClientRequest.PREFERENCE_TYPE;

public class ServicesClient{

	private static int PORT = 9001;
    private static String serverAddress = "localhost";
    
	synchronized public static ServicesClientResponse getServiceInfo(PREFERENCE_TYPE prefType, ZONE_TYPE zType) {
		 // Setup networking
        try {
        	
        	Socket socket;    	
        	socket = new Socket(serverAddress, PORT);
        	//socket.setSoTimeout(200);
        	ObjectOutputStream output = new ObjectOutputStream(socket.getOutputStream());
        	
        	ServicesClientRequest myPosition = new ServicesClientRequest(prefType,zType);
        	output.writeObject(myPosition);
	        output.flush();
	        
	        ObjectInputStream intput = new ObjectInputStream(socket.getInputStream());
			ServicesClientResponse info = null ;
			info = (ServicesClientResponse)intput.readObject();
			socket.close();
			return info;
			
		} catch (UnknownHostException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
        return null;
		// TODO Auto-generated constructor stub
	}
	
	public static void main(String arg[]){
		
		ServicesClient.getServiceInfo(PREFERENCE_TYPE.ALL, ZONE_TYPE.NONE);
	}
}